# Contributor: Bart Ribbers <bribbers@disroot.org>
# Maintainer: Bart Ribbers <bribbers@disroot.org>
pkgname=qt6-qtwebengine
pkgver=6.3.1
pkgrel=0
pkgdesc="Provides support for web applications using the Chromium browser project"
url="https://qt.io/"
# s390x blocked by qt6-qtdeclarative
# ppc64le not supported by chromium
# riscv64 blocked by nodejs
# 32-bit arches are blocked by memory exhaustion and "libblink_core.a: error adding symbols: file format not recognized"
arch="all !s390x !ppc64le !riscv64 !armv7 !x86 !armhf"
license="LGPL-2.1-only AND LGPL-3.0-only AND GPL-3.0-only AND Qt-GPL-exception-1.0"
depends_dev="
	alsa-lib-dev
	ffmpeg-dev
	icu-dev
	krb5-dev
	lcms2-dev
	libevent-dev
	libexecinfo-dev
	libvpx-dev>=1.10.0-r1
	libxkbfile-dev
	libxml2-dev
	libxslt-dev
	minizip-dev
	nss-dev
	opus-dev
	pciutils-dev
	pipewire-dev
	pulseaudio-dev
	qt6-qtbase-dev
	qt6-qtdeclarative-dev
	qt6-qtpositioning-dev
	qt6-qttools-dev
	qt6-qtwebchannel-dev
	re2-dev
	"
makedepends="$depends_dev
	bison
	bsd-compat-headers
	cmake
	flex
	gperf
	gzip
	nodejs
	perl
	py3-html5lib
	python3
	samurai
	"
subpackages="$pkgname-dev"
builddir="$srcdir/qtwebengine-everywhere-src-${pkgver/_/-}"

case $pkgver in
	*_alpha*|*_beta*|*_rc*) _rel=development_releases;;
	*) _rel=official_releases;;
esac

source="https://download.qt.io/$_rel/qt/${pkgver%.*}/${pkgver/_/-}/submodules/qtwebengine-everywhere-src-${pkgver/_/-}.tar.xz
	0001-Enable-building-on-musl.patch
	0002-musl-fixes.patch
	0003-qt-musl-mallinfo.patch
	0004-qt-musl-resolve.patch
	0005-qt-musl-crashpad.patch
	0006-musl-hacks.patch
	0007-musl-sandbox.patch
	0008-musl-stat.patch
	0009-close.patch
	default-pthread-stacksize.patch
	"

build() {
	cmake -B build -G Ninja \
		-DCMAKE_BUILD_TYPE=Release \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DINSTALL_BINDIR=lib/qt6/bin \
		-DINSTALL_DOCDIR=share/doc/qt6 \
		-DINSTALL_ARCHDATADIR=lib/qt6 \
		-DINSTALL_DATADIR=share/qt6 \
		-DINSTALL_INCLUDEDIR=include/qt6 \
		-DINSTALL_MKSPECSDIR=lib/qt6/mkspecs \
		-DINSTALL_EXAMPLESDIR=share/doc/qt6/examples \
		-DQT_FEATURE_webengine_system_alsa=ON \
		-DQT_FEATURE_webengine_system_ffmpeg=ON \
		-DQT_FEATURE_webengine_system_icu=ON \
		-DQT_FEATURE_webengine_system_libevent=ON \
		-DQT_FEATURE_webengine_system_libpci=ON \
		-DQT_FEATURE_webengine_system_libpng=ON \
		-DQT_FEATURE_webengine_system_libwebp=ON \
		-DQT_FEATURE_webengine_system_libxml=ON \
		-DQT_FEATURE_webengine_system_libxslt=ON \
		-DQT_FEATURE_webengine_system_minizip=ON \
		-DQT_FEATURE_webengine_system_opus=ON \
		-DQT_FEATURE_webengine_system_pulseaudio=ON \
		-DQT_FEATURE_webengine_system_zlib=ON \
		-DQT_FEATURE_webengine_proprietary_codecs=ON \
		-DQT_FEATURE_webengine_kerberos=ON \
		-DQT_FEATURE_webengine_webrtc_pipewire=ON
	SAMUFLAGS=-j12 cmake --build build
}

check() {
	cd build
	CTEST_OUTPUT_ON_FAILURE=TRUE ctest
}

package() {
	DESTDIR="$pkgdir" cmake --install build
}
sha512sums="
e00601a7ec6400551f7707d15cf326340ae8d6a5bb8cda55df4619148414f4b3ca3daabfd7263dd5a2ff2ca8ba64f9e91c9db3f1a50bea4903148c57b6dc81dd  qtwebengine-everywhere-src-6.3.1.tar.xz
9a05c07c4616053d247b1200cdd1883e8067babc5ab5bc169ea1599643d120c445fb4db586f5e247e122711f37e148d13fc8a7443d879877d7c82fb1f778db58  0001-Enable-building-on-musl.patch
0a75c7b5b9f195e0322f5a3177dfc9808ab0f712f9bb76d0738010a5c8e4f8a04de58d0db98b532eea41d7a996661b4e7fa197a1b1170adb45e5c2241cfbe2c8  0002-musl-fixes.patch
1275a2190d2b95a2fcd5b6bf12d983676c3d40d9101a73d12cad69bd3c88686d34dc1ec943f337a2bf05c802ef82ed8c93379c31a79cefdf5daf437ef5e34af1  0003-qt-musl-mallinfo.patch
263950bf35117746ba61feb8033f585347f77cf067be6c2f8f1e50754d972b9605ba97ed80f3149ba8e4d3e796303a785e37bb963beb2a86a642d9c2a09d881f  0004-qt-musl-resolve.patch
173c401e1a0daa7a1471880807e4fb0a74fc338a0f306dc067147878c29e7bb94cae43c37fe2bf21dd7a7ffd2d739697fd21d10c059ce647df01d8236612cc68  0005-qt-musl-crashpad.patch
909b7613d74ae17eb2d304b5481629e26fe1fa965f9f49aea25f6bc44b9fc35ea781e3f85e567498c7398f373ade7109b94f05b7e16f64d54243c5fe0211b279  0006-musl-hacks.patch
f7380e97018a93c786a95650646d135ceb326ecdb615ffdcb1ed004f1c2ca2e1da1a5b0729969b7f2fed60c8fa048b36db055df4cca4bdedc8a7060c65ac5bd7  0007-musl-sandbox.patch
9c7f9b9dd2d8e6b3e21b30921f526667fc2c244554f8fcb6f2d37c74c8ebe7ba4fe96a812a4ed916dc4c7bda0b06eb7b8f6dcea7a9178c956c0b69bfae44d5b2  0008-musl-stat.patch
484efce13cf1c918fb03f41cbf85d43c8811ba71876be85e8939441a299b918f12113ee93eb456fa8b5590326655b9fcd1fd2949c6a2f5edf81fe5ddb0e61255  0009-close.patch
f4cb20796922b6e26433a18ab2ba5dd8750e8bbfb479e9416a362073c9e6a3ac12ee9e9868f6c9335b374b9d8ca8bed2e322e5ac3fe694a6ec6ddce8bd9b801b  default-pthread-stacksize.patch
"
